********************************************************************************
********************************************************************************
************************** Project Contact with Police *************************
********************************** Estimations *********************************
********************************************************************************



global data "$path_data_clean\Police_clean.dta"


********************** Definition of variables of interest *********************


global treatments "contact photo anonymous police"
global outcomes "trust_pair trust_police trust_youth diff_trust IAT"
global expected "expected_pair expected_police expected_youth diff_expected" 
global altruism "dictator altruism_police"
global controls "gender age education victim* attention"
global police_feels "police_discrimination police_violence police_threat"


********************************************************************************
**************************** Descriptive statistics ****************************
********************************************************************************


{
use "$data", clear

sutex $treatments $outcomes $expected $altruism $controls $police_feels ///
	vocational technological general police_controls /// 
	, lab nobs minmax key(tab: descriptive) replace ///
	file("$path_tables\Descriptive.tex") title("Descriptive statistics")


}


********************************************************************************
**************************** Observations per class ****************************
********************************************************************************


{
use "$data", clear

collapse (count) count_obs = finished, by(classe)

su count_obs
}

********************************************************************************
*************************** Balance across treatments ***************************
********************************************************************************


{
use "$data", clear


*** Creating the table of balance ***

matrix ttests= (., ., ., ., ., ., ., ., ., ., ., .)

local n0 = 0
local n1 = 0
local n2 = 0

gen comp_ano_photo = 1 if photo == 1
replace comp_ano_photo = 0 if anonymous == 1

gen comp_ano_contact = 1 if contact == 1
replace comp_ano_contact = 0 if anonymous == 1

gen comp_photo_contact = 1 if contact == 1
replace comp_photo_contact = 0 if photo == 1

foreach var of varlist $controls police_controls {
	quietly ttest `var', by(comp_ano_photo)
	local n0 = max(r(N_1),`n0')
	local mu0 = r(mu_1)
	local n1 = max(r(N_2),`n1')
	local mu1 = r(mu_2)
	local diff01 = r(mu_2) - r(mu_1)
	local se01 = r(se)
	local p01 = r(p)
	quietly ttest `var', by(comp_ano_contact)
	local n2 = max(r(N_2),`n0')
	local mu2 = r(mu_2)
	local diff02 = r(mu_2) - r(mu_1)
	local se02 = r(se)
	local p02 = r(p)
	quietly ttest `var', by(comp_photo_contact)
	local diff12 = r(mu_2) - r(mu_1)
	local se12 = r(se)
	local p12 = r(p)

	matrix line`var' = (`mu0', `mu1', `mu2', `diff01', `se01', `p01', `diff02', `se02', `p02', `diff12', `se12', `p12')
	matrix rownames line`var' = `var'
	matrix ttests = (ttests \ line`var')
}

matrix lineN= (`n0', `n1', `n2', ., ., ., ., ., ., ., ., .)
matrix rownames lineN= N
matrix ttests = (ttests \ lineN)

matrix colnames ttests= Mean_anonymous Mean_photo Mean_contact Diff_anonymous_photo SE01 p01 Diff_anonymous_contact SE02 p02 Diff_photo_contact SE12 p12

outtable using "$path_tables\Balance", replace mat(ttests) format(%5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f) ///
	caption("Balance across treatments \label{tab: Balance}") nobox center 
*mat2txt, matrix(ttests) sav("$path_tables\Balance.xls") format(%5.3f %5.3f %5.3f %5.3f %5.4f) replace


*** Tests of normal distribution ***

svmat ttests
keep ttest*
drop if ttests1 == .
drop if _n == _N

local newnames Mean_anonymous Mean_photo Mean_contact Diff_anonymous_photo SE01 p01 Diff_anonymous_contact SE02 p02 Diff_photo_contact SE12 p12
local i = 1

foreach name in `newnames'{
	rename ttests`i' `name'
	local i = `i' + 1
}

swilk p01
swilk p02
swilk p12

clear all
}


********************************************************************************
********************* Treatment effect on primary outcomes *********************
********************************************************************************


{
*** Main regression table

{
use "$data", clear

** Effect on trust towards the individual met

reg trust_pair i.contact##i.police photo $controls, vce(cluster classe)
estimates store m1, title("Trust Pair")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on trust towards the police

reg trust_police i.contact##i.police photo $controls, vce(cluster classe)
estimates store m2, title("Trust Police")
quietly su trust_police if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on IAT

reg IAT i.contact##i.police photo $controls, vce(cluster classe)
estimates store m3, title("IAT")
quietly su IAT if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


estout m* using "$path_tables\Treatment_effect_primary.tex", style(tex) cells(b(star fmt(3)) se(par fmt(%9.3f))) starlevels(* 0.033 ** 0.017 *** 0.0033) ///
	legend label varlabels(_cons Constant) drop($controls) stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) title("Treatment effect on primary outcomes") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "Corrected p-values for three tests: * p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the amount sent in the trust game with the individual met, in column 2, the outcome is the amount sent in a trust game with a random police officer. In column 3, the outcome is the result of the Implicit Association Test. Controls include gender, level of education, age, indicators of whether the participant was victim of certain crimes and misdemeanors and the level of attention. Standard errors are clustered at the class level." "\end{table}") replace


estout m* using "$path_tables\Treatment_effect_primary_controls.tex", style(tex) cells(b(star fmt(3)) se(par fmt(%9.3f))) starlevels(* 0.033 ** 0.017 *** 0.0033) ///
	legend label varlabels(_cons Constant) stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) title("Treatment effect on primary outcomes (including controls)") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "Corrected p-values for three tests: * p<0.10, ** p<0.05, *** p<0.01. Corrected p-values for three one-tailed tests: * p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the amount sent in the trust game with the individual met, in column 2, the outcome is the amount sent in a trust game with a random police officer. In column 3, the outcome is the result of the Implicit Association Test. Standard errors are clustered at the class level." "\end{table}") replace


estimates clear

clear all
}



*** Histograms

{
** Trust pair

{
use "$data", clear

ranksum trust_pair if police == 1, by(contact)

collapse (mean) mean_trust = trust_pair (sd) sd_trust = trust_pair (count) n=trust_pair, by(treatment police)
gen high=mean_trust+invttail(n-1,0.025)*(sd_trust/sqrt(n))
gen low=mean_trust-invttail(n-1,0.025)*(sd_trust/sqrt(n))
gen treatper = 0 if treatment == 3
replace treatper= 2 if treatment == 2 & police == 0
replace treatper = 4 if treatment == 2 & police == 1
replace treatper = 6 if treatment == 1 & police == 0
replace treatper = 8 if treatment ==1 & police == 1

sort treatper

tw  (bar mean_trust treatper if treatper == 0, color("51 92 103")) ///
	(bar mean_trust treatper if treatper == 2, color("255 243 176")) ///
	(bar mean_trust treatper if treatper == 4, color("158 42 43")) ///
	(bar mean_trust treatper if treatper == 6, color("224 159 62")) ///
	(bar mean_trust treatper if treatper == 8, color("84 11 14")) ///
	(rcap high low treatper, color(black)), ///
	xlabel(0 " " , noticks) /// 
	ylabel(0(0.2).5) xtitle(" ") ///
	legend(order(1 "Control" 2 "Photo - No police" 3 "Photo - Police" 4 "Contact - No police" 5 "Contact - Police") cols(1))  ///
	ytitle("Mean share sent in Trust Game") graphregion(color(white))



graph export "$path_figures\histo_trust_pair.pdf", replace
graph export "$path_figures\histo_trust_pair.png", replace
window manage close graph

}

** Trust Police

{
use "$data", clear

ranksum trust_police if police == 1, by(contact)

collapse (mean) mean_trust = trust_police (sd) sd_trust = trust_police (count) n=trust_police, by(treatment police)
gen high=mean_trust+invttail(n-1,0.025)*(sd_trust/sqrt(n))
gen low=mean_trust-invttail(n-1,0.025)*(sd_trust/sqrt(n))
gen treatper = 0 if treatment == 3
replace treatper= 2 if treatment == 2 & police == 0
replace treatper = 4 if treatment == 2 & police == 1
replace treatper = 6 if treatment == 1 & police == 0
replace treatper = 8 if treatment ==1 & police == 1

sort treatper

tw  (bar mean_trust treatper if treatper == 0, color("51 92 103")) ///
	(bar mean_trust treatper if treatper == 2, color("255 243 176")) ///
	(bar mean_trust treatper if treatper == 4, color("158 42 43")) ///
	(bar mean_trust treatper if treatper == 6, color("224 159 62")) ///
	(bar mean_trust treatper if treatper == 8, color("84 11 14")) ///
	(rcap high low treatper, color(black)), ///
	xlabel(0 " " , noticks) /// 
	ylabel(0(0.2)0.5, noticks) xtitle(" ") ///
	legend(order(1 "Control" 2 "Photo - No police" 3 "Photo - Police" 4 "Contact - No police" 5 "Contact - Police") cols(1))  ///
	ytitle("Mean share sent in Trust Game") graphregion(color(white))

graph export "$path_figures\histo_trust_police.pdf", replace
window manage close graph

}


** IAT

{
use "$data", clear

ranksum IAT if police == 1, by(contact)

collapse (mean) mean_trust = IAT (sd) sd_trust = IAT (count) n=IAT, by(treatment police)
gen high=mean_trust+invttail(n-1,0.025)*(sd_trust/sqrt(n))
gen low=mean_trust-invttail(n-1,0.025)*(sd_trust/sqrt(n))
gen treatper = 0 if treatment == 3
replace treatper= 2 if treatment == 2 & police == 0
replace treatper = 4 if treatment == 2 & police == 1
replace treatper = 6 if treatment == 1 & police == 0
replace treatper = 8 if treatment ==1 & police == 1

sort treatper

tw  (bar mean_trust treatper if treatper == 0, color("51 92 103")) ///
	(bar mean_trust treatper if treatper == 2, color("255 243 176")) ///
	(bar mean_trust treatper if treatper == 4, color("158 42 43")) ///
	(bar mean_trust treatper if treatper == 6, color("224 159 62")) ///
	(bar mean_trust treatper if treatper == 8, color("84 11 14")) ///
	(rcap high low treatper, color(black)), ///
	xlabel(0 " " , noticks) /// 
	ylabel(-2(1)0, noticks) xtitle(" ") ///
	legend(order(1 "Control" 2 "Photo - No police" 3 "Photo - Police" 4 "Contact - No police" 5 "Contact - Police") cols(1))  ///
	ytitle(" ") graphregion(color(white))

graph export "$path_figures\histo_IAT.pdf", replace
window manage close graph

}




}



*** Graph of only treatment effects

{
use "$data", clear

matrix treatments = J(12,4,.)

** Coefficients
{

** First column: Outcome

forval i=1/12{
	local outcome = floor((`i'-1)/4 + 1)
	matrix treatments[`i',1] = `outcome'
}


** Second column: Treatment

forval i=1/12{
	local treatment = 1*(floor((`i'-1)/4)==(`i'-1)/4) + 2*(floor((`i'-2)/4)==(`i'-2)/4) + 3*(floor((`i'-3)/4)==(`i'-3)/4) + 4*(floor((`i'-4)/4)==(`i'-4)/4)
	matrix treatments[`i',2] = `treatment'
}


** Third and fourth columns: Regression coefficients

{
* Trust Pair

quietly su trust_pair if treatment == 3
local std = r(sd)
local i = 1

quietly reg trust_pair i.contact##i.police photo $controls, vce(cluster classe)

matrix treatments[4*(`i'-1)+1,3] = _b[photo]/`std'
matrix treatments[4*(`i'-1)+1,4] = _se[photo]/`std'

matrix treatments[4*(`i'-1)+2,3] = _b[1.police]/`std'
matrix treatments[4*(`i'-1)+2,4] = _se[1.police]/`std'

matrix treatments[4*(`i'-1)+3,3] = _b[1.contact]/`std'
matrix treatments[4*(`i'-1)+3,4] = _se[1.contact]/`std'

matrix treatments[4*(`i'-1)+4,3] = _b[1.contact#1.police]/`std'
matrix treatments[4*(`i'-1)+4,4] = _se[1.contact#1.police]/`std'


* Trust Police

quietly su trust_police if treatment == 3
local std = r(sd)
local i = 2

quietly reg trust_police i.contact##i.police photo $controls, vce(cluster classe)

matrix treatments[4*(`i'-1)+1,3] = _b[photo]/`std'
matrix treatments[4*(`i'-1)+1,4] = _se[photo]/`std'

matrix treatments[4*(`i'-1)+2,3] = _b[1.police]/`std'
matrix treatments[4*(`i'-1)+2,4] = _se[1.police]/`std'

matrix treatments[4*(`i'-1)+3,3] = _b[1.contact]/`std'
matrix treatments[4*(`i'-1)+3,4] = _se[1.contact]/`std'

matrix treatments[4*(`i'-1)+4,3] = _b[1.contact#1.police]/`std'
matrix treatments[4*(`i'-1)+4,4] = _se[1.contact#1.police]/`std'


* IAT

quietly su IAT if treatment == 3
local std = r(sd)
local i = 3

quietly reg IAT i.contact##i.police photo $controls, vce(cluster classe)

matrix treatments[4*(`i'-1)+1,3] = _b[photo]/`std'
matrix treatments[4*(`i'-1)+1,4] = _se[photo]/`std'

matrix treatments[4*(`i'-1)+2,3] = _b[1.police]/`std'
matrix treatments[4*(`i'-1)+2,4] = _se[1.police]/`std'

matrix treatments[4*(`i'-1)+3,3] = _b[1.contact]/`std'
matrix treatments[4*(`i'-1)+3,4] = _se[1.contact]/`std'

matrix treatments[4*(`i'-1)+4,3] = _b[1.contact#1.police]/`std'
matrix treatments[4*(`i'-1)+4,4] = _se[1.contact#1.police]/`std'

}

}

** Plot

{
matrix list treatments

svmat treatments

drop if _n>12

keep treatments*

ren treatments* var*
ren var1 outcome
ren var2 treatment
ren var3 effect
ren var4 sd
gen upper = min(effect + 2*sd,1)
gen lower = max(effect - 2*sd,-1)

gen treatper = treatment + 5*(outcome-1)


tw  (scatter effect treatper if treatment == 1, color("255 243 176")) ///
    (scatter effect treatper if treatment == 2, color("158 42 43")) ///
    (scatter effect treatper if treatment == 3, color("224 159 62")) ///
    (scatter effect treatper if treatment == 4, color("84 11 14")) ///
	(rcap upper lower treatper, color(black)), ///
	xlabel(2.75 "Trust Pair" 7.5 "Trust Police" 12.5 "IAT", noticks) /// 
	ylabel(-1(0.5)1, noticks) ///
	xtitle(" ") ///
	legend(order(1 "Photo x Student " 2 "Photo x Police" 3 "Contact x Student" 4 "Contact x Police") rows(2))  ///
	ytitle("Standardized treatment effect") ///
	yline(0, lcolor(black)) ///
	xline(5 10, lpattern(dash) lcolor(black)) ///
	graphregion(color(white))

graph export "$path_figures\coefs.pdf", replace
graph export "$path_figures\coefs.png", replace
window manage close graph

}


}



*** Regression with and without controls

{
use "$data", clear

** Effect on trust towards the individual met

* Without controls
reg trust_pair i.contact##i.police photo, vce(cluster classe)
estimates store m1, title("Trust Pair")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police

* With controls
reg trust_pair i.contact##i.police photo $controls, vce(cluster classe)
estimates store m2, title("Trust Pair")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on trust towards the police

* Without controls
reg trust_police i.contact##i.police photo, vce(cluster classe)
estimates store m3, title("Trust Police")
quietly su trust_police if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police

* With controls
reg trust_police i.contact##i.police photo $controls, vce(cluster classe)
estimates store m4, title("Trust Police")
quietly su trust_police if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on IAT

* Without controls
reg IAT i.contact##i.police photo, vce(cluster classe)
estimates store m5, title("IAT")
quietly su IAT if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police

* With controls
reg IAT i.contact##i.police photo $controls, vce(cluster classe)
estimates store m6, title("IAT")
quietly su IAT if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


*** Export table

estout m* using "$path_tables\Treatment_effect_no_controls.tex", style(tex) cells(b(star fmt(3)) se(par fmt(%9.3f))) starlevels(* 0.033 ** 0.017 *** 0.0033) ///
	legend label varlabels(_cons Constant) stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) title("Treatment effect on primary outcomes without controls") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "Corrected p-values for three tests: * p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the amount sent in the trust game with the individual met, in column 2, the outcome is the amount sent in a trust game with a random police officer. In column 3, the outcome is the result of the Implicit Association Test. Controls include gender, level of education, age, indicators of whether the participant was victim of certain crimes and misdemeanors and the level of attention. Standard errors are clustered at the class level." "\end{table}") replace


estimates clear

clear all
}

}

********************************************************************************
******************** Treatment effect on secondary outcomes ********************
********************************************************************************


{
*** Channels
{
use "$data", clear


*** Effect on expected amount sent back from pair

quietly reg expected_share_pair i.contact##i.police photo $controls, vce(cluster classe)
estimates store m1, title("Expected from pair")
quietly su expected_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


*** Effect on altruism pair

quietly reg dictator i.contact##i.police photo $controls, vce(cluster classe)
estimates store m2, title("Altruism pair")
quietly su dictator if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


*** Effect on expected amount sent back from the police

quietly reg expected_share_police i.contact##i.police photo $controls, vce(cluster classe)
estimates store m3, title("Expected from police")
quietly su expected_police if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


*** Effect on altruism towards the police

quietly probit altruism_police i.contact##i.police photo $controls, vce(cluster classe)
estimates store m4, title("Altruism police")
estadd scalar r2 = e(r2_p)
quietly su altruism_police if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


estout m* using "$path_tables\Treatment_secondary.tex", style(tex) ///
	cells(b(star fmt(3)) se(par fmt(%9.3f))) ///
	starlevels(* 0.1 ** 0.05 *** 0.01 ) ///
	legend label varlabels(_cons Constant) ///
	drop($controls) ///
	stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) ///
	title("Treatment effect on secondary outcomes") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "* p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the expected share of tokens sent back by the pair in a trust game. In column 2, the outcome is the amount sent in a dictator game to the pair. In column 3, the outcome is the difference between the expected share sent back by a random police officer or a random high-school student in a trust game. In column 4, the outcome is the probability to select the police association. Controls include gender, level of education, age, indicators of whether the participant was victim of certain crimes and misdemeanors and the level of attention. Standard errors are clustered at the class level." "\end{table}") replace

	
estout m* using "$path_tables\Treatment_secondary_controls.tex", style(tex) ///
	cells(b(star fmt(3)) se(par fmt(%9.3f))) ///
	starlevels(* 0.1 ** 0.05 *** 0.01 ) ///
	legend label varlabels(_cons Constant) ///
	stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) ///
	title("Treatment effect on primary outcomes (including controls)") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "* p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the expected share of tokens sent back by the pair in a trust game. In column 2, the outcome is the amount sent in a dictator game to the pair. In column 3, the outcome is the difference between the expected share sent back by a random police officer or a random high-school student in a trust game. In column 4, the outcome is the probability to select the police association. Standard errors are clustered at the class level." "\end{table}") ///
	replace


estimates clear

clear all

}


*** Stated beliefs about the police

{
use "$data", clear


*** Likelihood to report a crime

quietly reg report i.contact##i.police photo $controls, vce(cluster classe)
estimates store m1, title("Likelihood to report")
quietly su report if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


*** Police officer is an honorable career

quietly reg police_honorable i.contact##i.police photo $controls, vce(cluster classe)
estimates store m2, title("Police honorable")
quietly su police_honorable if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


*** Consider police as a career

quietly reg police_career i.contact##i.police photo $controls, vce(cluster classe)
estimates store m3, title("Police career")
quietly su police_career if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


*** Police non violent

quietly reg police_non_violent i.contact##i.police photo $controls, vce(cluster classe)
estimates store m4, title("Police non violent")
quietly su police_non_violent if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)

estout m* using "$path_tables\Police_outcomes.tex", style(tex) ///
	cells(b(star fmt(3)) se(par fmt(%9.3f))) ///
	starlevels(* 0.1 ** 0.05 *** 0.01 ) ///
	legend label varlabels(_cons Constant) ///
	drop($controls) ///
	stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) ///
	title("Treatment effect on views of the police") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "* p<0.10, ** p<0.05, *** p<0.01. For columns 1 through 3, the outcome is a variable from 1 to 4 on whether participants agree with the statement. In column 1, the statement is: Imagine in the future you are victim of theft. You are certain to report it to the police. In column 2, the statement is: I believe that police officer is an honorable career. In column 3, the statement is: I am considering a career as a police officer for my future. In the last column, the statement was: I believe police officers are violent. The outcome presented here is the opposite of the answer of participants (i.e. their disagreement with the statement). Standard errors are clustered at the class level." "\end{table}") ///
	replace
	
estimates clear
}


}


********************************************************************************
*************************** Police identity controls ***************************
********************************************************************************


{
*** Raw histogram
{
use "$data", clear

hist police_controls, width(1) graphregion(color(white))

graph export "$path_figures\histo_controls.pdf", replace
window manage close graph
}


*** Histogram with >10 bin

{
use "$data", clear

replace police_controls = 11 if police_controls > 10

hist police_controls, width(1) start(-0.5) graphregion(color(white)) ///
	xlabel(0 1 2 3 4 5 6 7 8 9 10 11 ">10", noticks)
	
graph export "$path_figures\histo_controls_bins.pdf", replace
window manage close graph
}


*** Cumulative distributions

{
cumul police_controls if anonymous == 1, gen(cumul_ano)
cumul police_controls if photo == 1, gen(cumul_photo)
cumul police_controls if contact == 1, gen(cumul_contact)

sort cumul_ano cumul_photo cumul_contact

tw (line cumul_ano police_controls)||(line cumul_photo police_controls)||(line cumul_contact police_controls), ///
	graphregion(color(white)) title("Cumulative function of police controls") ///
	legend(order(1 "Control" 2 "Photo" 3 "Contact")) ytitle("Cumulative") ///
	xscale(range(0 50)) xtitle(" ")

graph export "$path_figures\cumul_controls.pdf", replace
window manage close graph

}

}



********************************************************************************
**************************** Heterogeneity analysis ****************************
********************************************************************************


{

use "$data", clear

*** Heterogeneity with police controls 

quietly reg trust_pair i.contact##i.police##i.more_controls photo $controls, vce(cluster classe)
estimates store m2, title("Police interactions")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


*** Heterogeneity with gender

quietly reg trust_pair i.contact##i.police##i.gender photo $controls, vce(cluster classe)
estimates store m1, title("Gender")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


estout m* using "$path_tables\Heterogeneity.tex", style(tex) ///
	cells(b(star fmt(3)) se(par fmt(%9.3f))) ///
	starlevels(* 0.1 ** 0.05 *** 0.01 ) ///
	legend label varlabels(_cons Constant) ///
	drop($controls) ///
	stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) ///
	title("Heterogeneous treatment effect") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "* p<0.10, ** p<0.05, *** p<0.01. The outcome variable is the trust in the pair. Gender is coded as 1 for girls, 0 for boys. Standard errors are clustered at the class level." "\end{table}") ///
	replace

estout m2 using "$path_tables\Heterogeneity_controls.tex", style(tex) ///
	cells(b(star fmt(3)) se(par fmt(%9.3f))) ///
	starlevels(* 0.1 ** 0.05 *** 0.01 ) ///
	legend label varlabels(_cons Constant) ///
	stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) ///
	title("Heterogeneous treatment effect by police controls") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "* p<0.10, ** p<0.05, *** p<0.01. " "\end{table}") ///
	replace


estimates clear
}



********************************************************************************
******************************* Quantile analysis ******************************
********************************************************************************


{
use "$data", clear

matrix coefs = J(9,3,.)

forval i = 1/9 {
	local j = `i'/10
	quietly qreg2 trust_pair i.contact##i.police photo $controls, quantile(`j') cluster(classe)
	matrix coefs[`i',1] = _b[1.contact#1.police]
	matrix coefs[`i',2] = _se[1.contact#1.police]
	matrix coefs[`i',3] = `i'/10
}

matrix list coefs

svmat coefs

drop if _n>9

keep coefs*

ren coefs1 effect
ren coefs2 sd
ren coefs3 quant
gen upper = effect + 1.96*sd
gen lower = effect - 1.96*sd

twoway (line effect quant, lcolor("0 0 150")) || (line upper quant, lcolor("0 0 150") lpattern(dash)) || (line lower quant, lcolor("0 0 150") lpattern(dash)), ///
	yline(0, lstyle(color(black))) ///
	legend(off) ///
	xtitle("Quantile") ///
	ytitle("Quantile treatment effect") ///
	graphregion(color(white))

graph export "$path_figures\quantile.pdf", replace
window manage close graph


}



********************************************************************************
*********************** Comparison photo contact x police **********************
********************************************************************************


{
use "$data", clear


** Trust pair

quietly reg trust_pair i.contact##i.police $controls i.partner , vce(cluster classe)

estimates store m1, title("Trust Pair")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


** Trust Police

quietly reg trust_police i.contact##i.police $controls i.partner , vce(cluster classe)

estimates store m2, title("Trust Police")
quietly su trust_police if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


** IAT

quietly reg IAT i.contact##i.police $controls i.partner , vce(cluster classe)

estimates store m3, title("IAT")
quietly su IAT if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


** Table 

estout m* using "$path_tables\Comparison_photo_contact.tex", ///
	style(tex) ///
	cells(b(star fmt(3)) se(par fmt(%9.3f))) ///
	starlevels(* 0.1 ** 0.05 *** 0.01) ///
	legend ///
	label ///
	varlabels(_cons Constant) ///
	drop($controls *partner) ///
	stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) ///
	title("Comparison of Photo and Contact treatments") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") ///
	posthead(\midrule) ///
	prefoot(\midrule) ///
	postfoot("\end{tabular}" "\end{center}" "* p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the amount sent in the trust game with the individual met, in column 2, the outcome is the amount sent in a trust game with a random police officer. In column 3, the outcome is the result of the Implicit Association Test. Controls include gender, level of education, age, indicators of whether the participant was victim of certain crimes and misdemeanors and the level of attention. Partner-fixed effects are included. Standard errors are clustered at the class level." "\end{table}") ///
	replace


estimates clear

}


********************************************************************************
******************************* Robustness checks ******************************
********************************************************************************


{

*** Regression with class fixed effects
{
use "$data", clear

** Effect on trust towards the individual met

reg trust_pair i.contact##i.police photo $controls i.classe
estimates store m1, title("Trust Pair")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on trust towards the police

reg trust_police i.contact##i.police photo $controls i.classe
estimates store m2, title("Trust Police")
quietly su trust_police if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on IAT

reg IAT i.contact##i.police photo $controls i.classe
estimates store m3, title("IAT")
quietly su IAT if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


estout m* using "$path_tables\Treatment_effect_fixed.tex", style(tex) cells(b(star fmt(3)) se(par fmt(%9.3f))) starlevels(* 0.033 ** 0.017 *** 0.0033) ///
	legend label varlabels(_cons Constant) drop($controls i.classe*) stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) title("Treatment effect on primary outcomes") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "Corrected p-values for three tests: * p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the amount sent in the trust game with the individual met, in column 2, the outcome is the amount sent in a trust game with a random police officer. In column 3, the outcome is the result of the Implicit Association Test. Controls include gender, level of education, age, indicators of whether the participant was victim of certain crimes and misdemeanors and the level of attention. Standard errors are clustered at the class level." "\end{table}") replace


estimates clear

clear all

}


*** Tobit regressions primary outcomes
{
use "$data", clear

** Effect on trust towards the individual met

tobit trust_pair i.contact##i.police photo $controls, ll(0) ul(1) vce(cluster classe)
estimates store m1, title("Trust Pair")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on trust towards the police

tobit trust_police i.contact##i.police photo $controls, ll(0) ul(1) vce(cluster classe)
estimates store m2, title("Trust Police")
quietly su trust_police if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on IAT

reg IAT i.contact##i.police photo $controls, vce(cluster classe)
estimates store m3, title("IAT")
quietly su IAT if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


estout m* using "$path_tables\Tobit.tex", style(tex) cells(b(star fmt(3)) se(par fmt(%9.3f))) starlevels(* 0.033 ** 0.017 *** 0.0033) ///
	legend label varlabels(_cons Constant) drop($controls) stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) title("Treatment effect on primary outcomes") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "Corrected p-values for three one-tailed tests: * p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the amount sent in the trust game with the individual met, in column 2, the outcome is the amount sent in a trust game with a random police officer. In column 3, the outcome is the result of the Implicit Association Test. Controls include gender, level of education, age, indicators of whether the participant was victim of certain crimes and misdemeanors and the level of attention. Standard errors are clustered at the class level." "\end{table}") replace


estout m* using "$path_tables\Treatment_effect_primary_controls.tex", style(tex) cells(b(star fmt(3)) se(par fmt(%9.3f))) starlevels(* 0.033 ** 0.017 *** 0.0033) ///
	legend label varlabels(_cons Constant) stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) title("Treatment effect on primary outcomes (including controls)") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "Corrected p-values for three one-tailed tests: * p<0.10, ** p<0.05, *** p<0.01. Corrected p-values for three one-tailed tests: * p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the amount sent in the trust game with the individual met, in column 2, the outcome is the amount sent in a trust game with a random police officer. In column 3, the outcome is the result of the Implicit Association Test. Standard errors are clustered at the class level." "\end{table}") replace


estimates clear

clear all

}


*** Stated beliefs about the police

{
use "$data", clear

** Likelihood to report a crime
tobit report i.contact##i.police photo $controls, ll(1) ul(4) vce(cluster classe)
estimates store m1, title("Likelihood to report")
quietly su report if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


** Police officer is an honorable career
tobit police_honorable i.contact##i.police photo $controls, ll(1) ul(4) vce(cluster classe)
estimates store m2, title("Police honorable")
quietly su police_honorable if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


** Consider police as a career
tobit police_career i.contact##i.police photo $controls, ll(1) ul(4) vce(cluster classe)
estimates store m3, title("Police career")
quietly su police_career if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


** Police non violent
tobit police_non_violent i.contact##i.police photo $controls, ll(1) ul(4) vce(cluster classe)
estimates store m4, title("Police non violent")
quietly su police_non_violent if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)

estout m* using "$path_tables\Police_outcomes_tobit.tex", style(tex) ///
	cells(b(star fmt(3)) se(par fmt(%9.3f))) ///
	starlevels(* 0.1 ** 0.05 *** 0.01 ) ///
	legend label varlabels(_cons Constant) ///
	drop($controls) ///
	stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) ///
	title("Treatment effect on views of the police") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "* p<0.10, ** p<0.05, *** p<0.01. For columns 1 through 3, the outcome is a variable from 1 to 4 on whether participants agree with the statement. In column 1, the statement is: Imagine in the future you are victim of theft. You are certain to report it to the police. In column 2, the statement is: I believe that police officer is an honorable career. In column 3, the statement is: I am considering a career as a police officer for my future. In the last column, the statement was: I believe police officers are violent. The outcome presented here is the opposite of the answer of participants (i.e. their disagreement with the statement). Standard errors are clustered at the class level." "\end{table}") ///
	replace
	
estimates clear
}


*** Heterogeneity

{

use "$data", clear

** Heterogeneity with police controls 
tobit trust_pair i.contact##i.police##i.more_controls photo $controls, ll(0) ul(1) vce(cluster classe)
estimates store m2, title("Police interactions")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


** Heterogeneity with gender
tobit trust_pair i.contact##i.police##i.gender photo $controls, ll(0) ul(1) vce(cluster classe)
estimates store m1, title("Gender")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)


estout m* using "$path_tables\Heterogeneity_tobit.tex", style(tex) ///
	cells(b(star fmt(3)) se(par fmt(%9.3f))) ///
	starlevels(* 0.1 ** 0.05 *** 0.01 ) ///
	legend label varlabels(_cons Constant) ///
	drop($controls) ///
	stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) ///
	title("Heterogeneous treatment effect") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "* p<0.10, ** p<0.05, *** p<0.01. The outcome variable is the trust in the pair. Gender is coded as 1 for girls, 0 for boys. Standard errors are clustered at the class level." "\end{table}") ///
	replace


estimates clear

clear all
}


*** With attention checks

{
use "$data", clear

** Effect on trust towards the individual met

reg trust_pair i.contact##i.police photo $controls if attention == 1, vce(cluster classe)
estimates store m1, title("Trust Pair")
quietly su trust_pair if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on trust towards the police

reg trust_police i.contact##i.police photo $controls if attention == 1, vce(cluster classe)
estimates store m2, title("Trust Police")
quietly su trust_police if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


** Effect on IAT

reg IAT i.contact##i.police photo $controls if attention == 1, vce(cluster classe)
estimates store m3, title("IAT")
quietly su IAT if treatment == 3
estadd scalar mn = r(mean)
estadd scalar std = r(sd)
lincom 1.contact#1.police - 1.police


estout m* using "$path_tables\Treatment_effect_attention.tex", style(tex) cells(b(star fmt(3)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	legend label varlabels(_cons Constant) drop($controls) stats(r2 N mn std, fmt(%9.3f %9.0f %9.3f %9.3f) labels("\$R^2\$" "No. obs" "Mean Control" "Std dev. Control")) ///
	mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) title("Treatment effect on primary outcomes") ///
	prehead("\begin{table}[htbp]" "\begin{center}" "\caption{@title}" "\begin{tabular}{l*{@M}{rr}}" "\toprule") posthead(\midrule) ///
	prefoot(\midrule) postfoot("\end{tabular}" "\end{center}" "* p<0.10, ** p<0.05, *** p<0.01. In column 1, the outcome variable is the amount sent in the trust game with the individual met, in column 2, the outcome is the amount sent in a trust game with a random police officer. In column 3, the outcome is the result of the Implicit Association Test. Controls include gender, level of education, age, indicators of whether the participant was victim of certain crimes and misdemeanors and the level of attention. Standard errors are clustered at the class level." "\end{table}") replace


estimates clear

clear all
}


}


********************************************************************************
************************************ THE END ***********************************
********************************************************************************
